clear

*set to current directory
cd "analysis for replication"

**Delete or comment out if you don't want a log file (and log close at end of script)
log using "LL_log_analyses.smcl", replace

use "lockwood_lieberman_incentives.dta"




** ANALYSES PRESENTED IN MAIN PAPER

** incentives separated
	foreach outvar of varlist started finished  progress{

	areg `outvar' cash lottery ANC DA EFF prev_surveyed new_councillor, absorb(Municipality_code)
	estimates store estall_`outvar'
		
	areg `outvar' cash lottery prev_surveyed new_councillor if ANC==1, absorb(Municipality_code)
	estimates store estanc_`outvar'

	areg `outvar' cash lottery  prev_surveyed new_councillor if DA==1, absorb(Municipality_code)
	estimates store estda_`outvar'

	areg `outvar' cash lottery  prev_surveyed new_councillor if EFF==1, absorb(Municipality_code)
	estimates store esteff_`outvar'
		
	areg `outvar' cash lottery prev_surveyed new_councillor if DA==0 & ANC==0 & EFF==0, absorb(Municipality_code)
	estimates store estothr_`outvar'
	
	
}

set scheme sj

**Figure 1:
coefplot estall_started estall_progress estall_finished  , drop(_cons prev_surveyed new_councillor ANC DA EFF) xline(0) ///
plotlabels("Start survey"  "Percent complete" "finished survey") bylabels("All Councillors" ) xlabel (-.1(.05).1) levels(95 90)


graph export "figure1.png", as(png) name("Graph") replace


**Figure 2:

coefplot estanc_started   estanc_progress estanc_finished || estda_started   estda_progress estda_finished || esteff_started   esteff_progress esteff_finished  || estothr_started   estothr_progress estothr_finished , drop(_cons prev_surveyed new_councillor ANC DA EFF) xline(0) ///
plotlabels("Start survey"  "Percent complete" "finished survey") bylabels("ANC Councillors"  "DA Councillors" "EFF Councillors" "Other Councillors")  levels(95 90) xlabel (-.2(.05).1)

graph export "figure2.png", as(png) name("Graph") replace


***********************************
** ANALYSES PRESENTED IN APPENDIX *
***********************************


est clear
		// descriptive_stats \\ 
estpost tabstat anyincent cash lottery started finished finish_start progress ANC DA EFF new_councillor prev_surveyed Female Black White Coloured Indian_Asian, c(stat) stat(mean sd min max n)

esttab using "descriptive_stats.tex", replace ///
	  cells("mean(fmt(%6.3fc)) sd(fmt(%6.3fc)) min max count(fmt(%6.0fc))")   nonumber ///
	  nonote noobs label  ///
	  collabels("Mean" "SD" "Min" "Max" "N")  ///
	  title("Descriptive Statistics \label{table1stata}")
	  
	  
			// balance tables \\ 
			
est clear



iebaltab ANC DA new_councillor prev_surveyed, grpvar(Incentive) vce(robust) onerow rowvarlabels savetex("Balance.tex") replace



			// regression tables \\ 



*H1.1* 
est clear	
*thin
eststo: reg started anyincent ANC DA EFF , r
 estadd local  FE  "No"

*unadjusted 
eststo: reg started anyincent, r
 estadd local  FE  "No"

*w additional
eststo: areg started anyincent ANC DA EFF prev_surveyed new_councillor, absorb(Municipality_code) r
 estadd local  FE  "Yes"
 
esttab using "h1_1.tex", replace  ///
 b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Hypothesis 1.1 (Started)  \label{table1_1stata}") 

*H1.2* 
est clear
eststo clear

 *thin
eststo: reg finished  anyincent ANC DA EFF , r
 estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg finished   anyincent, r
 estadd local  FE  "No"

 *w additional
eststo: areg finished   anyincent ANC DA EFF prev_surveyed new_councillor, absorb(Municipality_code)
 estadd local  FE  "Yes"

*** PARENTHETICALLY....NOT PRE-REG... CONDITIONAL ON STARTING THE SURVEY

 *thin
eststo: reg finish_start anyincent ANC DA EFF , r
 estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg finish_start  anyincent, r
 estadd local  FE  "No"

 *w additional
eststo: areg finish_start  anyincent ANC DA EFF prev_surveyed new_councillor, absorb(Municipality_code)
 estadd local  FE  "Yes"
 

esttab using "h1_2.tex", replace   ///
 b(3) se(3) ///
 mgroups("A" "B", pattern(1 0 0 1 0 0)) ///
 alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label compress addnotes("A: Not Conditioned on Starting the Survey, B: Conditional on Starting the Survey") ///
 scalars( "FE Municipality FE") sfmt(3 0) /// 
 title("Hypothesis 1.2 (Finished)  \label{table1stata}") 

 
*H1.3* 

estimates clear 

 *thin
eststo: reg progress anyincent ANC DA EFF , r
 estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg progress  anyincent, r
 estadd local  FE  "No"

 *w additional
eststo: areg progress  anyincent ANC DA EFF prev_surveyed new_councillor, absorb(Municipality_code)
 estadd local  FE  "Yes"


esttab using "h1_3.tex", replace  ///
 b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Hypothesis 1.3 (Progress) \label{table1stata}") 

 
 
 ** H2 starts here ** 
 
*H2.1* 
est clear	
*thin
eststo: reg started lottery ANC DA EFF if anyincent==1, r
 estadd local  FE  "No"

*unadjusted 
eststo: reg started lottery, r
 estadd local  FE  "No"

*w additional
eststo: areg started lottery ANC DA EFF prev_surveyed new_councillor if anyincent==1, absorb(Municipality_code) r
 estadd local  FE  "Yes"
 
esttab using "h2_1.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Hypothesis 2.1 (started) Effect of lottery relative to cash \label{table1stata}") 

 

*H2.2* 
est clear

 *thin
eststo: reg finished  lottery ANC DA EFF if anyincent==1 , r
estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg finished   lottery if anyincent==1, r
 estadd local  FE  "No"

 *w additional
eststo: areg finished   lottery ANC DA EFF prev_surveyed new_councillor if anyincent==1, absorb(Municipality_code)
 estadd local  FE  "Yes"

*** PARENTHETICALLY....NOT PRE-REG... CONDITIONAL ON STARTING THE SURVEY

 *thin
eststo: reg finish_start lottery ANC DA EFF if anyincent==1, r
 estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg finish_start  lottery if anyincent==1, r
 estadd local  FE  "No"

 *w additional
eststo: areg finish_start  lottery ANC DA EFF prev_surveyed new_councillor if anyincent==1, absorb(Municipality_code)
 estadd local  FE  "Yes"
 

esttab using "h2_2.tex", replace  ///
 b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "FE Municipality FE") sfmt(3 0)
 
 esttab using "h2_2.tex", replace   ///
 b(3) se(3) ///
 mgroups("A" "B", pattern(1 0 0 1 0 0)) ///
 alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label compress addnotes("A: Not Conditioned on Starting the Survey, B: Conditional on Starting the Survey") ///
 scalars( "FE Municipality FE") sfmt(3 0) /// 
 title("Hypothesis 2.2 (started) Effect of lottery relative to cash \label{table1stata}") 

 
 
*H2.3* 

estimates clear 

 *thin
eststo: reg progress lottery ANC DA EFF if anyincent==1
 estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg progress  lottery, r
estimates store no_adjust
 estadd local  FE  "No"

 *w additional
eststo: areg progress  lottery ANC DA EFF prev_surveyed new_councillor if anyincent==1, absorb(Municipality_code)
 estadd local  FE  "Yes"


esttab using "h2_3.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Hypothesis 2.3 (Progress)  Effect of lottery relative to cash \label{table1stata}") 

 
 *** full sample ***
 
						
			
 
 ** H2 starts here ** 
 
*H2.1* 
est clear	
*thin
eststo: reg started lottery cash ANC DA EFF , r
 estadd local  FE  "No"

*unadjusted 
eststo: reg started lottery cash, r
 estadd local  FE  "No"

*w additional
eststo: areg started lottery cash ANC DA EFF prev_surveyed new_councillor , absorb(Municipality_code) r
 estadd local  FE  "Yes"
 
esttab using "h2_1b.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Hypothesis 2.1 (started) lottery and cash relative to no incentive \label{table1stata}") 

 

*H2.2* 
est clear

 *thin
eststo: reg finished  lottery cash ANC DA EFF  , r
estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg finished   lottery cash , r
 estadd local  FE  "No"

 *w additional
eststo: areg finished   lottery cash ANC DA EFF prev_surveyed new_councillor , absorb(Municipality_code)
 estadd local  FE  "Yes"

*** PARENTHETICALLY....NOT PRE-REG... CONDITIONAL ON STARTING THE SURVEY

 *thin
eststo: reg finish_start lottery cash ANC DA EFF , r
 estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg finish_start  lottery cash , r
 estadd local  FE  "No"

 *w additional
eststo: areg finish_start  lottery cash ANC DA EFF prev_surveyed new_councillor , absorb(Municipality_code)
 estadd local  FE  "Yes"
 

esttab using "h2_2b.tex", replace  ///
 b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "FE Municipality FE") sfmt(3 0)
 
 esttab using "h2_2b.tex", replace   ///
 b(3) se(3) ///
 mgroups("A" "B", pattern(1 0 0 1 0 0)) ///
 alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label compress addnotes("A: Not Conditioned on Starting the Survey, B: Conditional on Starting the Survey") ///
 scalars( "FE Municipality FE") sfmt(3 0) /// 
 title("Hypothesis 2.2 (started) lottery and cash relative to no incentive \label{table1stata}") 

 
 
*H2.3* 

estimates clear 

 *thin
eststo: reg progress lottery cash ANC DA EFF 
 estadd local  FE  "No"
 
 
 *w no adjustment
eststo: reg progress  lottery cash, r
estimates store no_adjust
 estadd local  FE  "No"

 *w additional
eststo: areg progress  lottery cash ANC DA EFF prev_surveyed new_councillor , absorb(Municipality_code)
 estadd local  FE  "Yes"


esttab using "h2_3b.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Hypothesis 2.3 (Progress)  lottery and cash relative to no incentive \label{table1stata}") 

    
  
 
 
 
 ** Other threats to validity as specified in the Pre-Analysis Plan 
  
    
  
 
 
 // By parties \\

 
 ** IN LATEX MANUALLY REMOVED THE BASE CATEGORIES
set showbaselevels off, permanently
set showomitted off, permanently
 
 **analyses using interaction effects
 est clear
 
 foreach outvar of varlist started finished  progress{

 	eststo: reg `outvar' anyincent##majorparty prev_surveyed new_councillor 
	estimates store estallinteract_`outvar'

 }
 
  esttab using "parties_interaction.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Interaction of Party and Incentive  \label{tableAstata}") ///
 
 
 
**any incentive: ANC 
est clear
foreach outvar of varlist started finished  progress{

 eststo: areg `outvar' anyincent prev_surveyed new_councillor if ANC==1, absorb(Municipality_code)
	 estadd local  FE  "Yes"

}
 
 esttab using "ANC_anyincent.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("ANC Only  \label{table1stata}") ///
 
 
**any incentive DA 

est clear
foreach outvar of varlist started finished  progress{

	eststo: areg `outvar' anyincent prev_surveyed new_councillor if DA==1, absorb(Municipality_code)
	 estadd local  FE  "Yes"

}	


 esttab using "DA_anyincent.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("DA Only  \label{table1stata}") ///

  
**any incent Other Parties 
	est clear
foreach outvar of varlist started finished  progress{

	eststo:areg `outvar' anyincent prev_surveyed new_councillor if DA==0 & ANC==0, absorb(Municipality_code)
	 estadd local  FE  "Yes"

}	


 esttab using "OtherParties_anyincent.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Other Parties: Any Incentive \label{table1stata}") ///
  
  
  
  
  
  // reg tables for the main graph \\ 
  
** cash lottery all parties 

est clear
foreach outvar of varlist started finished  progress{

 eststo: areg `outvar' cash lottery prev_surveyed new_councillor, absorb(Municipality_code)
	 estadd local  FE  "Yes"

}
 
 esttab using "All_cash_lottery.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("All Parties \label{table1stata}") ///
   
** cash lottery: ANC 
est clear
foreach outvar of varlist started finished  progress{

 eststo: areg `outvar' cash lottery prev_surveyed new_councillor if ANC==1, absorb(Municipality_code)
	 estadd local  FE  "Yes"

}
 
 esttab using "ANC_cash_lottery.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("ANC Only \label{table1stata}") ///
 
** cash lottery DA 
est clear
foreach outvar of varlist started finished  progress{

	eststo: areg `outvar' cash lottery prev_surveyed new_councillor if DA==1, absorb(Municipality_code)
	 estadd local  FE  "Yes"

}	


 esttab using "DA_cash_lottery.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("DA Only  \label{table1stata}") ///

  
**cash lottery Other Parties 
	est clear
foreach outvar of varlist started finished  progress{

	eststo:areg `outvar' cash lottery prev_surveyed new_councillor if DA==0 & ANC==0, absorb(Municipality_code)
	 estadd local  FE  "Yes"

}	


 esttab using "OtherParties_cash_lottery.tex", replace  ///
 b(3) se(3) ///
  alignment(D{.}{.}{-1}) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  compress ///
 scalars( "FE Municipality FE") sfmt(3 0) ///
  title("Other Parties (Not ANC or DA)  \label{table1stata}") ///
  
  
  *** ADDITIONAL ROBUSTNESS ***
  
  
  *Robust 1: Effects of RA's and RA Change
  
est clear	

eststo: areg started anyincent ANC DA EFF prev_surveyed new_councillor  , absorb(ResearchAssistant_code) r
 estadd local  Outcome  "started"
 estadd local  FE  "RA"

 
 eststo: areg finished  anyincent ANC DA EFF prev_surveyed new_councillor  , absorb(ResearchAssistant_code) r
 estadd local  Outcome  "finished"
 estadd local  FE  "RA"
 
 eststo: areg progress  anyincent ANC DA EFF prev_surveyed new_councillor  , absorb(ResearchAssistant_code) r
 estadd local  Outcome  "progress"
 estadd local  FE  "RA"
 

eststo: reg started anyincent ANC DA EFF prev_surveyed new_councillor RAChange 
 estadd local  Outcome  "started"
 estadd local  FE  "None"

 
 eststo: reg finished  anyincent ANC DA EFF prev_surveyed new_councillor RAChange 
 estadd local  Outcome  "finished"
 estadd local  FE  "None"

 
 eststo: reg progress  anyincent ANC DA EFF prev_surveyed new_councillor RAChange
 estadd local  Outcome  "progress"
 estadd local  FE  "None"

 
 
 
 
  esttab using "robust1.tex", replace  ///
 b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "Outcome" "FE") sfmt(3 0) ///
   title("Robustness to RA Change and RA Fixed Effects  \label{robust1stata}") ///

 
 
 
 
   
  *Robust 2: Effects of timing of events
  
est clear	
*thin
eststo: areg started anyincent ANC DA EFF prev_surveyed new_councillor i.month_contact, absorb(Municipality_code) r
 estadd local  Outcome  "started"

 
 eststo: areg finished anyincent ANC DA EFF prev_surveyed new_councillor i.month_contact, absorb(Municipality_code) r
 estadd local  Outcome  "finished"

 
 eststo: areg progress anyincent ANC DA EFF prev_surveyed new_councillor i.month_contact, absorb(Municipality_code) r
 estadd local  Outcome  "progress"

 
  esttab using "robust2.tex", replace  ///
 b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "Outcome") sfmt(3 0) ///
    title("Robustness to timing of enumeration  \label{robust2stata}") ///

 
 * Robust 3: Logit for binary outcomes
 
 ** incentives separated

 est clear
 
	eststo: logit started anyincent
 estadd local  Sample  "All"
		
	eststo: logit started anyincent if ANC==1
 estadd local  Sample  "ANC"

	eststo: logit started anyincent if DA==1
 estadd local  Sample  "DA"

	eststo: logit started anyincent if EFF==1
 estadd local  Sample  "EFF"
		
	eststo: logit started anyincent if DA==0 & ANC==0 & EFF==0
 estadd local  Sample  "Small"
	

//
//   esttab keep(cash lottery ANC DA EFF prev_surveyed new_councillor)  using "robust3.tex", replace  ///
  esttab using "robust3.tex", replace  ///
  b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "Sample") sfmt(3 0) ///
    title("Robustness to Logistic estimation for binary outcomes  \label{robust3stata}") ///


	
   
  *Robust 4: Mode of initial contact
  
est clear	
*thin
eststo: areg started anyincent ANC DA EFF prev_surveyed new_councillor i.first_contact, absorb(Municipality_code) r
 estadd local  Outcome  "started"

 
 eststo: areg finished anyincent ANC DA EFF prev_surveyed new_councillor i.first_contact, absorb(Municipality_code) r
 estadd local  Outcome  "finished"

 
 eststo: areg progress anyincent ANC DA EFF prev_surveyed new_councillor i.first_contact, absorb(Municipality_code) r
 estadd local  Outcome  "progress"

 
  esttab using "robust4.tex", replace  ///
 b(3) se(3) ///
 star(* 0.10 ** 0.05 *** 0.01) ///
 label  nomtitle collabels(none) compress ///
 scalars( "Outcome") sfmt(3 0) ///
    title("Robustness to mode of first contact  \label{robust4stata}") ///

 
	
	
 log close 
